package com.sisyphus.simple.activities;

import android.content.Intent;
import android.os.Bundle;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.sisyphus.simple.R;
import com.sisyphus.simple.SimpleAppActivityListTemplate;
import com.sisyphus.simple.adapters.PostListAdapter;
import com.sisyphus.simple.data.DataRepository;
import com.sisyphus.simple.data.network.model.Post;
import com.sisyphus.spinach.core.INetPageTask;
import com.sisyphus.spinach.ui.configs.IListTemplateProvider;
import com.sisyphus.spinach.ui.configs.impl.IPageTemplate;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

/**
 * 帖子列表
 */
public class PostListActivity extends AppCompatActivity implements IListTemplateProvider<Post> {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_post_list);

        findViewById(R.id.button_favorite).setOnClickListener(v ->
                startActivity(new Intent(this, FavoritePostListActivity.class)));

        provider().view(this);
    }


    @Override
    public IPageTemplate<Post> provider() {
        return new SimpleAppActivityListTemplate<Post>(findViewById(R.id.refresh_layout)) {

            @Override
            public INetPageTask.Presenter<Post, INetPageTask.View<Post>> presenter() {
                return DataRepository.getInstance().posts();
            }

            @Override
            public BaseQuickAdapter<Post, BaseViewHolder> adapter(RecyclerView recyclerView) {
                return new PostListAdapter();
            }

        };
    }

}
